package cn.fl.customer.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.utils.EncryptUtil;
import cn.fl.system.service.ISysDictionaryService;
import cn.fl.system.vo.SysDictionaryVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstCorpTeamService;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.service.ICstNpSocialRlService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstCorpTeamVO;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.customer.vo.CstNpSocialRlVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import fl.customer.facade.customer.condition.CstCorpTeamQueryCondition;
import fl.customer.facade.customer.condition.CstNpSocialRlQueryCondition;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.customer.facade.customer.dto.CstNpSocialRlDTO;

/**
 * @Description: 自然人社会关系信息表 控制层
 */
@Controller
@RequestMapping("/customer/cstnpsocialrl")
public class CstNpSocialRlController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CstNpSocialRlController.class);

	/**
	 * CstNpSocialRl 服务层BEAN
	 */
	@Autowired
	private ICstNpSocialRlService cstNpSocialRlService;
	
	/**
	 * CstBscInfo 服务层BEAN
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;
	
	/**
	 * CstCorpTeam 服务层BEAN
	 */
	@Autowired
	private ICstCorpTeamService cstCorpTeamService;
	
	@Autowired
	private ICstNpBscInfoService cstNpBscInfoService;

	@Autowired
	private ISysDictionaryService sysDictionaryService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		ModelAndView view = new ModelAndView("customer/cstnpsocialrl/custCstNpSocialRlList");
		view.addObject("cstId", cstId);
		BaseLogUtils.info(logger, "toListPage", "社会关系信息表页面跳转");
		return view;
	}

	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		String rId = request.getParameter("rId");
		logger.info("加载CstNpSocialRl toAddPage页面.");
		ModelAndView view = new ModelAndView("customer/cstnpsocialrl/custCstNpSocialRlAdd");
		//关系
		List<KeyValueVO> rlTypCdList = this.cstNpSocialRlService.searchRlTypCdList();
		view.addObject("searchSelectRlTypCdList", rlTypCdList);
		// 性别状况
		List<KeyValueVO> genderCdList = this.cstBscInfoService.searchGenderCdList();
		view.addObject("searchSelectGenderCdList", genderCdList);
		//证件类型
		List<KeyValueVO> certTypCdList = this.cstBscInfoService.searchCertTypCdList(CustomerConstant.CST_TYP_CD_NP);
		view.addObject("searchSelectCertTypCdList", certTypCdList);
		//是否实际还款人
		List<KeyValueVO> isActualPayerList = this.cstBscInfoService.searchIsActualPayerCdList();
		view.addObject("searchIsActualPayerCdList", isActualPayerList);
		//民族
		List<KeyValueVO> searchNationCdList = sysDictionaryService.getKvList(DictionaryConstant.CODE_GRP_CST_NATION_CD,CurrentThreadContext.getFlServiceSysCd(),"0000");
		view.addObject("searchNationCdList", searchNationCdList);
		view.addObject("cstId", cstId);
		view.addObject("rId", rId);
		return view;
	}
	
	/**
	 * 到详细页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String rId = request.getParameter("rId");
		logger.info("加载CstNpSocialRl toAddPage页面.");
		ModelAndView view = new ModelAndView("customer/cstnpsocialrl/custCstNpSocialRlDetail");
		view.addObject("rId", rId);
		return view;
	}
	

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstId = request.getParameter("cstId");
		String isEncrypt=request.getParameter("isEncrypt");

		if(StringUtils.isEmpty(cstId)){
			ListPageVO<CstNpSocialRlVO> listPage = new ListPageVO<CstNpSocialRlVO>(new ArrayList<CstNpSocialRlVO>(), 0);
			return listPage;
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		//判断客户是否自然人
		String cstTypCd = "";
		CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(Long.valueOf(cstId));
		if(cstBscInfoVO!=null){
			if(StringUtils.isNotBlank(cstBscInfoVO.getCstTypCd())){
				cstTypCd = cstBscInfoVO.getCstTypCd();
			}
		}
		CstNpSocialRlQueryCondition qc = new CstNpSocialRlQueryCondition();
		//如果是法人 获取团队中法人代表  主键ID作为cstId 存入社会关系中
		if(cstTypCd.equals(CustomerConstant.CST_TYP_CD_CORP)){
			CstCorpTeamQueryCondition condition = new CstCorpTeamQueryCondition();
			condition.setCstId(Long.valueOf(cstId));
			condition.setmTypCd(CustomerConstant.CST_CORP_TEAM_LOWER);
			condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
			List<CstCorpTeamVO> cstCorpTeamVOs =  this.cstCorpTeamService.searchList(condition);
			if(CollectionUtils.isNotEmpty(cstCorpTeamVOs)){
				CstCorpTeamVO cstCorpTeamVO = cstCorpTeamVOs.get(0);
				List<Long> cstIdList = new ArrayList<>();
				cstIdList.add(cstCorpTeamVO.getId());
				//qc.setRlTypCd(SysDictionaryConstant.CODE_GRP_RL_TYP_CD_5);//默认配偶信息
				qc.setCstIdList(cstIdList);
			}else{
				ListPageVO<CstNpSocialRlVO> listPage = new ListPageVO<CstNpSocialRlVO>(new ArrayList<CstNpSocialRlVO>(), 0);
				return listPage;
			}
		}else{
			List<Long> cstIdList = new ArrayList<>();
			cstIdList.add(Long.valueOf(cstId));
			//qc.setRlTypCd(SysDictionaryConstant.CODE_GRP_RL_TYP_CD_5);//默认配偶信息
			qc.setCstIdList(cstIdList);
		}
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		page.setCondition(qc);
		Pager pager = this.cstNpSocialRlService.searchListPage(page);
		List<CstNpSocialRlVO> list = (List<CstNpSocialRlVO>) pager.getResultList();
		ListPageVO<CstNpSocialRlVO> listPage = null;
		int totalCount=pager.getTotalCount();
		if(cstTypCd.equals(CustomerConstant.CST_TYP_CD_NP)){//自然人添加本人
			//判断本人信息是否已在联系人信息中，如果不在添加显示出
			CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(Long.valueOf(cstId));
			Boolean rtn=this.checkCstIsExist(list,cstNpBscInfoVO);
			if(!rtn) {
				CstNpSocialRlVO cstNpSocialRlVO=this.getCstNpScBscInfo(cstBscInfoVO,cstNpBscInfoVO);
				list.add(cstNpSocialRlVO);
				totalCount=totalCount + 1;
			}
		}
		String roleIsEncrypt=this.sysDictionaryService.getRoleisEncrypt();
		if(StringUtils.isNotEmpty(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(roleIsEncrypt)){
			for (CstNpSocialRlVO vo:list) {
				vo.setMp(EncryptUtil.mobileEncrypt(vo.getMp()));
				vo.setCertNo(EncryptUtil.certNoEncrypt(vo.getCertNo()));
			}
		}
		listPage = new ListPageVO<CstNpSocialRlVO>(list, totalCount);

		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功");
		if(StringUtils.isEmpty(id) || !StringUtils.isNumeric(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("参数不完整！");
			return result;
		}
		try {
			List<Long> ids = new ArrayList<>();
			ids.add(Long.valueOf(id));
			this.cstNpSocialRlService.removeByIds(ids);
			logger.debug("==remove==id:" + id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("删除失败");
			logger.error("删除失败!", ex);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String isEncrypt = request.getParameter("isEncrypt");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("参数不完整！");
			return result;
		}
		
		try {
			CstNpSocialRlVO vo = this.cstNpSocialRlService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在！");
			}else{
				String roleIsEncrypt=this.sysDictionaryService.getRoleisEncrypt();
				if (StringUtils.isNotEmpty(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(roleIsEncrypt)) {
					vo.setCertNo(EncryptUtil.certNoEncrypt(vo.getCertNo()));
					vo.setMp(EncryptUtil.mobileEncrypt(vo.getMp()));
				}
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取数据失败！");
			logger.error("获取数据失败！", ex);
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		try {
			CstNpSocialRlVO cstNpSocialRlVO = getRequestParams(request);
			cstNpSocialRlVO.setCrtTm(new Date());
			cstNpSocialRlVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			cstNpSocialRlVO.setIsDel(BaseConstant.IS_YESNO_NO);
			
			//检查配偶信息是否已经录入,如果录入则不能新增
			if(DictionaryConstant.CODE_GRP_RL_TYP_CD_5.equals(cstNpSocialRlVO.getRlTypCd())){
				CstNpSocialRlQueryCondition condition = new CstNpSocialRlQueryCondition();
				List<Long> cstIdList = new ArrayList<>();
				cstIdList.add(cstNpSocialRlVO.getCstId());
				condition.setCstIdList(cstIdList);
				condition.setRlTypCd(DictionaryConstant.CODE_GRP_RL_TYP_CD_5);
				List<CstNpSocialRlDTO> cstNpSocialRlDTOList = this.cstNpSocialRlService.searchList(condition);
				if(CollectionUtils.isNotEmpty(cstNpSocialRlDTOList)){
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("配偶信息已经存在,不能新增!");
					return result;
				}
			//如果为本人，进行三要素校验
			}else if(CustomerConstant.CST_RL_TYPE_CD_7.equals(cstNpSocialRlVO.getRlTypCd())){
				try {
                    Boolean rtn = this.cstNpSocialRlService.checkCustThreeElements(cstNpSocialRlVO.getRlNm(), cstNpSocialRlVO.getCertNo(), cstNpSocialRlVO.getMp());
                    if (rtn) {
                        BaseLogUtils.info(logger, "add", "手机号三要素检测成功");
                        cstNpSocialRlVO.setMpStsCd(CustomerConstant.CST_CHECK_STS_D_1);
                        cstNpSocialRlVO.setLivAudStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                        if (StringUtils.isNotEmpty(cstNpSocialRlVO.getCstId()) && StringUtils.isNotEmpty(cstNpSocialRlVO.getMp())) {
                            BaseLogUtils.info(logger, "add", "手机号三要素校验成功，更新自然人手机号 id:" + cstNpSocialRlVO.getCstId());
                            BaseLogUtils.info(logger, "add", "手机号三要素校验成功，更新自然人手机号 mp:" + cstNpSocialRlVO.getMp());
                            CstNpBscInfoVO cstNpBscInfoVO = new CstNpBscInfoVO();
                            cstNpBscInfoVO.setId(cstNpSocialRlVO.getCstId());
                            cstNpBscInfoVO.setMp1(cstNpSocialRlVO.getMp());
                            this.cstNpBscInfoService.modify(cstNpBscInfoVO);
							result.setData(cstNpSocialRlVO.getMp());
                        }
                    } else {
                        BaseLogUtils.info(logger, "add", "手机号三要素检测成功");
                        cstNpSocialRlVO.setMpStsCd(CustomerConstant.CST_CHECK_STS_D_2);
                        cstNpSocialRlVO.setLivAudStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                    }
                }catch (BaseException e){
                    BaseLogUtils.error(logger, "add", "手机号三要素检测异常"+e.getMessage(),e);
                    cstNpSocialRlVO.setMpStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                    cstNpSocialRlVO.setLivAudStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                }catch (Exception e){
                    BaseLogUtils.error(logger, "add", "手机号三要素检测异常"+e.getMessage(),e);
                    cstNpSocialRlVO.setMpStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                    cstNpSocialRlVO.setLivAudStsCd(CustomerConstant.CST_CHECK_STS_D_0);
                }
			}
			BaseLogUtils.info(logger, "add", "新增参数：", JSONObject.toJSONString(cstNpSocialRlVO));
			Long id = this.cstNpSocialRlService.add(cstNpSocialRlVO);
			if(StringUtils.isEmpty(id)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("新增失败!");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			logger.error(ex.getMessage(), ex);
		}

		return result;
	}

	/**
	 * 获取请求参数
	 */
	private CstNpSocialRlVO getRequestParams(HttpServletRequest request) {
		String rlTypCd = request.getParameter("rlTypCd");//关系
		String rlNm = request.getParameter("rlNm");//名字
		String mp = request.getParameter("mp");//手机号
		String workPlc = request.getParameter("workPlc");//工作单位
		String pos = request.getParameter("pos");//职位
		String tel = request.getParameter("tel");//单位电话
		String certTypCd = request.getParameter("certTypCd");//证件类型
		String certNo = request.getParameter("certNo");//证件号码
		String homeAddr = request.getParameter("homeAddr");//现居住地
		String workAddr = request.getParameter("workAddr");//单位地址
		String cstId = request.getParameter("cstId");//客户ID
		String genderCd = request.getParameter("genderCd");//性别
		String zipNo = request.getParameter("zipNo");//通讯地址邮编
		String idAddr = request.getParameter("idAddr");//身份证地址
		String postAddr = request.getParameter("postAddr");//通讯地址
		String rlRem = request.getParameter("rlRem");//备注
		String isActualPayer = request.getParameter("isActualPayer");//是否实际还款人
		String nation = request.getParameter("nation");//民族

		if(StringUtils.isEmpty(cstId) || !StringUtils.isNumeric(cstId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请确保客户信息存在后在进行操作!");
		}
		
		if(StringUtils.isEmpty(rlTypCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请选择关系!");
		}
		
		if(StringUtils.isEmpty(rlNm) || rlNm.length() > 50 || !StringUtils.isCustomerName(rlNm)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "姓名不能为空,支持格式[艾合买提•倪格提],并且长度不能大于20个字符。");
		}
		
		if(StringUtils.isEmpty(genderCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请选择性别!");
		}
		
		if(StringUtils.isNotEmpty(mp) && !StringUtils.checkMobileNumber(mp)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写正确的手机号!");
		}
		
		if(StringUtils.isNotEmpty(tel) && !StringUtils.isFixedPhone(tel)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写正确的电话号码!");
		}
		
		if (StringUtils.isBlank(certTypCd)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请选择证件类型!");
		}

		/*if (StringUtils.isBlank(certNo)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "证件号码不能为空!");
		}*/

		if (StringUtils.isNotEmpty(certNo) && certTypCd.equals(DictionaryConstant.CODE_CERT_TYP_CD_0) && !StringUtils.isIdCardNumber(certNo)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请输入正确的身份证号码!");
		}
		
		CstNpSocialRlVO entity = new CstNpSocialRlVO();
		entity.setRlTypCd(rlTypCd);
		entity.setRlNm(rlNm);
		entity.setMp(mp);
		entity.setWorkPlc(workPlc);
		entity.setPos(pos);
		entity.setTel(tel);
		entity.setCertTypCd(certTypCd);
		entity.setCertNo(certNo);
		entity.setHomeAddr(homeAddr);
		entity.setWorkAddr(workAddr);
		entity.setNation(nation);
		String cstTypCd = "";
		CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(Long.valueOf(cstId));
		if(cstBscInfoVO!=null){
			if(StringUtils.isNotBlank(cstBscInfoVO.getCstTypCd())){
				cstTypCd = cstBscInfoVO.getCstTypCd();
			}
		}
		if(cstTypCd.equals(CustomerConstant.CST_TYP_CD_CORP)){
			CstCorpTeamQueryCondition condition = new CstCorpTeamQueryCondition();
			condition.setCstId(Long.valueOf(cstId));
			condition.setmTypCd(CustomerConstant.CST_CORP_TEAM_LOWER);
			condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
			List<CstCorpTeamVO> cstCorpTeamVOs =  this.cstCorpTeamService.searchList(condition);
			if(CollectionUtils.isNotEmpty(cstCorpTeamVOs)){
				CstCorpTeamVO cstCorpTeamVO = cstCorpTeamVOs.get(0);
				entity.setCstId(cstCorpTeamVO.getId());
			}else{
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "该法人团队信息不存在法人代表！");
			}
		}else{
			entity.setCstId(Long.valueOf(cstId));
		}
		entity.setGenderCd(genderCd);
		entity.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		entity.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		entity.setZipNo(zipNo);
		entity.setIdAddr(idAddr);
		entity.setPostAddr(postAddr);
		entity.setRlRem(rlRem);
		if(StringUtils.isNotBlank(isActualPayer)){
			entity.setIsActualPayer(Integer.valueOf(isActualPayer));
		}
		return entity;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"修改成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("参数不完整！修改主键不存在!");
			return result;
		}
		try {
			CstNpSocialRlVO cstNpSocialRlVO = getRequestParams(request);
			cstNpSocialRlVO.setMdfTm(new Date());
			cstNpSocialRlVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			cstNpSocialRlVO.setId(Long.valueOf(id));
			boolean success = this.cstNpSocialRlService.modify(cstNpSocialRlVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败！");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("修改失败!");
			logger.error("修改失败!", ex);
		}
		return result;
	}

	/**
	 * @MethodName checkCstIsExist
	 * @Description: 验证联系人中手机号是否已存在
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/6/19 16:43
	 * @Version: V1.0.0
	 * @Param list
	 * @Param cstNpBscInfoVO
	 * @Return java.lang.Boolean
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private Boolean checkCstIsExist(List<CstNpSocialRlVO> list,CstNpBscInfoVO cstNpBscInfoVO){
		BaseLogUtils.info(logger,"checkCstIsExist","验证本人的手机号是否已在联系人中:cstId"+cstNpBscInfoVO.getId());
		Boolean rtn=false;
		if(CollectionUtils.isNotEmpty(list) && null != cstNpBscInfoVO){
			String mp1 = cstNpBscInfoVO.getMp1();
			if(StringUtils.isNotEmpty(mp1)) {
				for (CstNpSocialRlVO cstNpSocialRlVO : list) {
					//联系人中手机号存在，并且是本人
					if (mp1.equals(cstNpSocialRlVO.getMp()) && "7".equals(cstNpSocialRlVO.getRlTypCd())) {
						rtn=true;
						break;
					}
				}
			}
		}
		BaseLogUtils.info(logger,"checkCstIsExist","验证本人的手机号是否已在联系人中:验证结果"+rtn);
		return rtn;
	}

	/**
	 * @MethodName getCstNpScBscInfo
	 * @Description: 封装本人的联系人信息
	 * @Author: wangpengtao@lionbridgecapital.cn
	 * @CreateDate: 2019/6/19 16:33
	 * @Version: V1.0.0
	 * @Param cstId
	 * @Param cstBscInfoVO
	 * @Return cn.fl.customer.vo.CstNpSocialRlVO
	 * @UpdateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	private CstNpSocialRlVO getCstNpScBscInfo(CstBscInfoVO cstBscInfoVO,CstNpBscInfoVO cstNpBscInfoVO){
		BaseLogUtils.info(logger,"getCstNpScBscInfo","封装本人联系人信息处理开始");
		CstNpSocialRlVO cstNpSocialRlVO = new CstNpSocialRlVO();
		if(StringUtils.isNotBlank(cstBscInfoVO.getCertTypCd())){
			//证件类型
			List<KeyValueVO> certTypCdList = this.cstBscInfoService.searchCertTypCdListZj(CustomerConstant.CST_TYP_CD_NP,CustomerConstant.CST_TYP_CD_NP);
			for(KeyValueVO keyValueVO : certTypCdList){
				if(keyValueVO.getKey().equals(cstBscInfoVO.getCertTypCd())){
					cstNpSocialRlVO.setCertTypCdNm(keyValueVO.getValue());
					break;
				}
			}
		}
		cstNpSocialRlVO.setId(cstBscInfoVO.getId());
		cstNpSocialRlVO.setCertTypCd(cstBscInfoVO.getCertTypCd());
		cstNpSocialRlVO.setCertNo(cstBscInfoVO.getCertNo());
		cstNpSocialRlVO.setWorkAddr(cstNpBscInfoVO.getWorkAddr());
		cstNpSocialRlVO.setPos(cstNpBscInfoVO.getPosCdNm());
		cstNpSocialRlVO.setMp(cstNpBscInfoVO.getMp1());
		cstNpSocialRlVO.setRlNm(cstBscInfoVO.getCstNm());
		cstNpSocialRlVO.setRlTypCd("7");
		cstNpSocialRlVO.setRlTypCdNm("本人");
		cstNpSocialRlVO.setLivAudStsCdNm("未检测");
		cstNpSocialRlVO.setMpStsCdNm("未检测");
		BaseLogUtils.info(logger,"getCstNpScBscInfo","封装本人联系人信息处理结束");
		return cstNpSocialRlVO;
	}

}

